home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-04-25 | 9.7 KB | 308 lines | [TEXT/CWIE] |
- /*
- File: DAM_StdCommands.c
-
- Contains: All builder routines for SCSI CDBs.
-
- Version: 1.0
-
- Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
-
- */
-
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // All direct device access functions
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #include "USB_StdCommands.h"
-
- #pragma mark --
- #pragma mark ATAPI/SCSI Device Commands
- // Expects numBytes of at least eight for write protect check
- OSStatus ModeSenseBuilder(IntDriveRequestPBPtr requestPB, UInt8 CommandSet, UInt8 *Buffer, UInt8 modePage, UInt8 numBytes)
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
- BlockZero( Buffer, numBytes );
-
- if( CommandSet == kRBCCommand )
- {
- commandPB->cdb[0] = kCmdModeSense6;
- commandPB->cdb[1] = 0x08; // Disable Block Descriptors (as per RBC)
- commandPB->cdb[2] = modePage; // Say we want the current settings for modePage
- commandPB->cdb[4] = numBytes;
- }
- else
- {
- commandPB->cdb[0] = kCmdModeSense10;
- commandPB->cdb[2] = modePage;
- commandPB->cdb[8] = numBytes;
- }
-
- commandPB->flags = kStorageDataIn; // -> Expect a data in transfer
- commandPB->userBuffer = (Ptr) Buffer; // -> Pointer to user buffer
- commandPB->expectedCount = numBytes; // -> Expected number of bytes to transfer
- commandPB->completionProc = &DeviceRequestCompletion; // -> Completion routine
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
-
- // Send Diagnostics acts as a reset on UFI devices
- OSStatus SendDiagnosticBuilder( IntDriveRequestPBPtr requestPB )
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
-
- commandPB->cdb[0] = kCmdSendDiagnostic;
- commandPB->cdb[1] = 0x04;
- #if 0
- commandPB->cdb[2] = 0xFF;
- commandPB->cdb[3] = 0xFF;
- commandPB->cdb[4] = 0xFF;
- commandPB->cdb[5] = 0xFF;
- commandPB->cdb[6] = 0xFF;
- commandPB->cdb[7] = 0xFF;
- commandPB->cdb[8] = 0xFF;
- commandPB->cdb[9] = 0xFF;
- commandPB->cdb[10] = 0xFF;
- commandPB->cdb[11] = 0xFF;
- #endif
- commandPB->flags = kStorageNoData; // -> Expect a data in transfer
- commandPB->userBuffer = nil; // -> Pointer to user buffer
- commandPB->expectedCount = 0x00; // -> Expected number of bytes to transfer
- commandPB->completionProc = &DeviceRequestCompletion; // -> Completion routine
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
-
- // Expects no buffer
- OSStatus TestUnitReadyBuilder( IntDriveRequestPBPtr requestPB )
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
-
- commandPB->flags = kStorageNoData;
- commandPB->completionProc = &DeviceRequestCompletion;
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
- OSStatus RequestSenseBuilder( IntDriveRequestPBPtr requestPB, Ptr senseData )
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
-
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
- BlockZero( senseData, kSenseStandardDataSize);
-
- commandPB->cdb[0] = kCmdRequestSense;
- commandPB->cdb[4] = kSenseStandardDataSize;
- commandPB->flags = kStorageDataIn; // -> Expect a data in transfer
- commandPB->userBuffer = senseData; // -> Pointer to user buffer
- commandPB->expectedCount = kSenseStandardDataSize; // -> Expected number of bytes to transfer
- commandPB->completionProc = &DeviceRequestCompletion; // -> Completion routine
-
-
- status = SendDeviceRequest(commandPB);
-
- return status;
- }
-
- // Examine the data returned by Request Sense and if valid data was returned, but
- // fewer than 18 bytes, fix it so that it looks like all data was returned.
- // If no error occurred on the command, just return without doing anything.
- void FixRequestSenseData( IntDriveRequestPBPtr requestPB )
- {
- if ( requestPB->status != noErr )
- {
- if ( requestPB->executePB.actualCount >= 13 )
- {
- // Enough data was returned to have a valid ASC and ASCQ
- // go ahead and pad the data.
- BlockZero((Ptr) (((UInt32) requestPB->executePB.userBuffer) + requestPB->executePB.actualCount),
- requestPB->executePB.expectedCount-requestPB->executePB.actualCount);
-
- // Update the actual count field
- requestPB->executePB.actualCount = requestPB->executePB.expectedCount;
-
- // Act like no error occurred
- requestPB->status = noErr;
- }
- }
- }
-
- // Expects buffer of at least InqDataLength
- OSStatus InquiryBuilder(IntDriveRequestPBPtr requestPB, UInt8 *Buffer, UInt8 InqDataLength)
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
-
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
- BlockZero( Buffer, InqDataLength);
-
- commandPB->cdb[0] = kCmdInquiry;
- commandPB->cdb[4] = InqDataLength;
- commandPB->flags = kStorageDataIn; // -> Expect a data in transfer
- commandPB->userBuffer = (Ptr) Buffer; // -> Pointer to user buffer
- commandPB->expectedCount = InqDataLength; // -> Expected number of bytes to transfer
- commandPB->completionProc = &DeviceRequestCompletion; // -> Completion routine
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
- // Expects a buffer of size ReadCapacityData
- OSStatus GetMediaGeometryBuilder(IntDriveRequestPBPtr requestPB, ReadCapacityData *getGeometry)
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
-
- getGeometry->TotalBlocksOnMedia = 0;
- getGeometry->BlockLengthInBytes = 0;
-
- commandPB->cdb[0] = kCmdReadCapacity;
- commandPB->flags = kStorageDataIn; // -> Expect a data in transfer
- commandPB->userBuffer = (Ptr) getGeometry; // -> Pointer to user buffer
- commandPB->expectedCount = sizeof(ReadCapacityData); // -> Expected number of bytes to transfer
- commandPB->completionProc = &DeviceRequestCompletion; // -> Completion routine
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
-
- // Expects a buffer of at least 0x0C (12)
- OSStatus ReadFormatCapacityBuilder(IntDriveRequestPBPtr requestPB, UInt8 *Buffer, UInt8 numBytes)
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
-
- commandPB->cdb[0] = kCmdReadFormatCapacities;
- commandPB->cdb[7] = 0;
- commandPB->cdb[8] = numBytes;
- commandPB->flags = kStorageDataIn; // -> Expect a data in transfer
- commandPB->userBuffer = (Ptr) Buffer; // -> Pointer to user buffer
- commandPB->expectedCount = numBytes; // -> Expected number of bytes to transfer
- commandPB->completionProc = &DeviceRequestCompletion; // -> Completion routine
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
- OSStatus FormatFloppyTrackBuilder( IntDriveRequestPBPtr requestPB, UInt8 *Buffer, UInt32 FormatCapacity, UInt16 blockSize, UInt8 TrackNum, UInt8 Side)
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
-
- BlockZero( Buffer, 0x0C);
-
- // Set up the data going out
- // First set up the Defect List Header
- Buffer[0] = 0;
- Buffer[1] = 0x80 | 0x20 | 0x10 | Side;
- Buffer[2] = 0;
- Buffer[3] = 0x08;
-
- *((UInt32 *) &Buffer[4]) = FormatCapacity;
- *((UInt16 *) &Buffer[10]) = blockSize;
-
- commandPB->cdb[0] = kCmdFormat;
- commandPB->cdb[1] = 0x17;
- commandPB->cdb[2] = TrackNum;
- commandPB->cdb[8] = 0x0C;
- commandPB->flags = kStorageDataOut | kStorageUseCommandCompletionInt; // -> Expect a data out transfer and wait for interrupt
- commandPB->userBuffer = (Ptr) Buffer; // -> Pointer to user buffer
- commandPB->expectedCount = 0x0C; // -> Expected number of bytes to transfer
- commandPB->completionProc = &DeviceRequestCompletion; // -> Completion routine
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
-
- OSStatus StartStopEjectCartridgeBuilder(IntDriveRequestPBPtr requestPB, Boolean StartDrive, Boolean doEject)
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
-
- commandPB->cdb[0] = kCmdStartStopUnit;
- if( doEject )
- {
- commandPB->cdb[4] = 0x02; // Unload the Media
- }
- else if ( StartDrive )
- {
- commandPB->cdb[4] = 0x01; // Start the Drive
- }
- else
- {
- commandPB->cdb[4] = 0x00; // Stop the drive, but don't eject
- }
-
-
- commandPB->flags = kStorageNoData; // -> Expect no data transfer
- commandPB->userBuffer = nil; // -> Pointer to user buffer
- commandPB->expectedCount = 0; // -> Expected number of bytes to transfer
- commandPB->completionProc = (StorageClassCompletionProcPtr) &DeviceRequestCompletion; // -> Completion routine
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
-
- OSStatus PreventAllowRemovalBuilder(IntDriveRequestPBPtr requestPB, Boolean preventRemoval )
- {
- OSStatus status = noErr;
- StorageExecuteCommandPB *commandPB;
-
- commandPB = &requestPB->executePB;
- BlockZero( commandPB, sizeof(StorageExecuteCommandPB));
-
- commandPB->cdb[0] = kCmdPreventAllowRemoval;
- if ( preventRemoval == true )
- {
- commandPB->cdb[4] = 0x01; // Prevent Media Removal
- }
- else
- {
- commandPB->cdb[4] = 0x00; // Allow Media Removal
- }
-
- commandPB->flags = kStorageNoData; // -> Expect no data transfer
- commandPB->userBuffer = nil; // -> Pointer to user buffer
- commandPB->expectedCount = 0; // -> Expected number of bytes to transfer
- commandPB->completionProc = &DeviceRequestCompletion; // -> Completion routine
-
- status = SendDeviceRequest(commandPB);
- return status;
- }
-
-